#include<bits/stdc++.h>
using namespace std;
const int N=1e5+1e2;
struct car{
	int d,v,a;
}a[N];
int n,m,L,V;
int p[N];
int main(){
	freopen("detect.in","r",stdin);
	freopen("detect.out","w",stdout);
	int T;
	cin>>T;
	while(T--)
	{
		cin>>n>>m>>L>>V;
		for(int i=1;i<=n;i++)
		cin>>a[i].d>>a[i].v>>a[i].a;
		for(int i=1;i<=m;i++)
		cin>>p[i];
		int f=1;
		for(int i=1;i<=n;i++)
		{
			if(a[i].v>V&&a[i].d<=p[m])
			{
				f=0;
				break;
			}
		}
		if(f==0)
		cout<<m-1;
		else
		cout<<m;
	}
	return 0;
}
